var express = require('express');
var router = express.Router();

router.post('/', function (req, res, next) {

    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("Content-Type", "application/json;charset=utf-8");

    let one = JSON.parse(Object.keys(req.body)[0])
    let data = {
        code: 1,
        msg: '成功',
        data: one
    }
    // console.log(one)

    var mysql = require('mysql')
    var connection = mysql.createConnection({
        host: 'localhost',
        port: '3306', //端口号
        user: 'root',
        password: '654321',
        database: 'db1'
    })
    connection.connect()
    connection.query("DELETE FROM user where id=?", data.data.id, function (error, results, fields) {
        if (error) {
            console.log("数据库访问出错", error);
        } else {
            res.send(data);
        }
    })
    connection.end()

});

module.exports = router;